interface Goods {
  readonly id:number;
  name: string;
  price: number;
  disCount?: number
}

const good: Goods = {
  id: 123,
  name: "平板",
  price: 2999,
  disCount: 0.6
}
// 定义函数类型
interface BuyGoods {
  (good: Goods, balance: number): boolean 
}

const buy: BuyGoods = (good, balance) => {
  if (balance >= (good.disCount ? good.disCount * good.price : good.price)) {
    return true
  } else {
    return false
  }
}

console.log(buy(good, 1000))

interface scoreRank {
  [name: string]: number,
  examId: number,
  sum: 1000
  // teacher: string // ts2411
}

interface TestIndex {
  [name: string]: string,
  // [rank: number]: number // ts2411
}

interface exportGoods {
  sendGoods: (demand: number, supply: number ) => boolean
}
interface importGoods {
  buy: (good: Goods) => void
}
class Bussinessman implements exportGoods, importGoods {
  name: string
  goods: Goods[]
  
  constructor(name: string) {
    this.name = name;
    this.goods = []
  }

  sendGoods(demand: number, supply: number) {
    if (demand <= supply) {
      return true;
    }
    return false;
  }
  buy(good: Goods) {
    this.goods.push(good);
  }
}

const pb = new Bussinessman('wpb')
console.log(pb.sendGoods(100, 1000))
console.log(pb.name)
pb.buy({
  id: 12123,
  name: 'ipad',
  price: 2889
})
console.log(pb.goods)